package com.my.designPattern_old;

/**
 * 单例模式之四：兼顾线程安全及效率的写法
 * 双重检查
 */
public class Singleton4 {

    private static volatile Singleton4 singleton4;

    private Singleton4(){}

    public static Singleton4 getSingleton4(){
        if(singleton4 == null){
            synchronized (Singleton4.class){
                if(singleton4 == null){
                    return new Singleton4();
                }
            }
        }
        return singleton4;
    }
}
